#pragma once

#include "item_id.h"

namespace icache {

//common interface for all caches in the library
class cache {
public:
	virtual ~cache() { }
	virtual void put(cached_image_sptr const & c, last_used_position p = most_recently_used) = 0;
	///never returns empty pointer
	virtual cached_image_sptr get(item_id_sptr const & id, last_used_position p = most_recently_used) = 0;
	///may return empty pointer if no item was found
	virtual cached_image_sptr try_get(item_id_sptr const & id, last_used_position p = most_recently_used) = 0;
	///returns true if requested item is present in the cache;
	virtual bool touch(item_id_sptr const & id, last_used_position p = most_recently_used) = 0;
	virtual void remove(item_id_sptr const & id) = 0;
	virtual void purge() = 0; ///< clears all elements in the cache but do not closes it
};

/** Methods get(...), try_get(...), touch(...) are quite similar.
	get(...) is the slowest among them, because if the item is not in cache it invokes is.load() and saves item in the cache;
	try_get(...) may load and return only image stored in the cache;
	touch(...) do not perform any long cache operation (if you don't ask to delete an item), and only reports avalability of an item.
	However, remember that the state of cache may be changed after return from touch(...) by other threads.
	Also touch(...) does nothing if the item is currently used by other thread (even if it is being deleted).
*/

} //namespace icache
